﻿using System;

public class Mapper232 : MapperDefault
{
    internal int[] regs232 = new int[2];

    public override void init(NES nes)
    {
        base.init(nes);
        this.reset();
    }

    public override void loadROM(ROM rom)
    {
        if (rom.Valid)
        {
            int romBankCount = rom.RomBankCount;
            this.loadRomBank(this.regs232[0] | this.regs232[1], 0x8000);
            this.loadRomBank(this.regs232[0] | 3, 0xc000);
            this.loadCHRROM();
            this.loadBatteryRam();
            base.nes.Cpu.requestIrq(2);
        }
    }

    public override void reset()
    {
        this.regs232[0] = 12;
        this.regs232[1] = 0;
    }

    public override void write(int address, short value_Renamed)
    {
        if (address < 0x8000)
        {
            base.write(address, value_Renamed);
        }
        else if (address == 0x9000)
        {
            this.regs232[0] = (value_Renamed & 0x18) >> 1;
        }
        else if ((0xa000 <= address) && (address <= 0xffff))
        {
            this.regs232[1] = value_Renamed & 3;
        }
        this.loadRomBank(this.regs232[0] | this.regs232[1], 0x8000);
        this.loadRomBank(this.regs232[0] | 3, 0xc000);
    }
}

